package com.chenshu.test;

import com.chenshu.Obj;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * Created with IntelliJ IDEA
 * Description：
 * User：chenshu
 * Date：2024-03-26
 * Time：20:23
 */
public class Reflection03 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        String ClassPathName = "com.chenshu.Obj";
        //1.通过全限定类名获得Class对象
        Class clazz = Class.forName(ClassPathName);
        //2.输出clazz
        System.out.println(clazz);//打印clazz是哪个类的Class对象
        System.out.println(clazz.getClass());//输出clazz运行类型 java.lang.Class
        //3. 得到包名
        System.out.println(clazz.getPackage().getName());
        //4. 得到全限定类名
        System.out.println(clazz.getName());
        //5. 通过cls创建对象实例
        Obj obj = (Obj) clazz.newInstance();
        System.out.println(obj);
    }
}
